package com.twl.ws.web;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.twl.app.base.servlet.BankAccount;
import com.twl.app.base.servlet.PeripheralFunction;
import com.twl.app.base.util.GsonUtils;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;
import com.twl.facade.web.PeripheralService;

/**
 * 外部接口
 * @author Xu
 *
 */
@Service
public class PeripheralServiceImpl implements PeripheralService {

	@Autowired
	private WSHibernateDaoSupportProxy wsHibernateDaoSupportProxy;

	@Override
	public String getBankAccount(String empNo) {
		BankAccount bankAccountEntity = new BankAccount();
		bankAccountEntity.setEmpno(empNo);

		bankAccountEntity.setFunction(PeripheralFunction.GET_BANK_ACCOUNT.getFunction());

		try {
			String hql1 = "select count(*) from Uemp where delstaff=0 and staffint = '" + empNo + "'";
			Long count = (Long) wsHibernateDaoSupportProxy.uniqueResult(hql1);

			String bankAccount = null;
			if (0 == count) {
				bankAccountEntity.setEmpnoexist(false);
			} else {
				bankAccountEntity.setEmpnoexist(true);
				String hql2 = "select accback from Uemp where delstaff=0 and staffint = '" + empNo + "'";
				bankAccount = (String) wsHibernateDaoSupportProxy.uniqueResult(hql2);
			}

			if (StringUtils.isNotBlank(bankAccount)) {
				bankAccountEntity.setAccountexist(true);
				bankAccountEntity.setBankaccount(bankAccount);
			} else {
				bankAccountEntity.setAccountexist(false);
				bankAccountEntity.setBankaccount("");
			}
			bankAccountEntity.setSuccess(true);
			bankAccountEntity.setErrmsg("");
		} catch (Exception e) {
			bankAccountEntity.setEmpnoexist(false);
			bankAccountEntity.setAccountexist(false);
			bankAccountEntity.setBankaccount("");
			bankAccountEntity.setSuccess(false);
			bankAccountEntity.setErrmsg("查询失败...");
			e.printStackTrace();
		}

		return GsonUtils.toJson(bankAccountEntity);
	}

}
